<template>
    <view class="body">
        <!-- <rf-nav-bar class="head_bar" color="color: #111110;" backgroundColor="#fff" :title="title" /> -->
        <view class="backTitle">
            <image class="bg-image" src="../../static/icon/p_040.png" mode="widthFix"></image>
            <view class="titleLeft">
                <p>用户编号：{{dataFile.merchantNo}}</p>
                <p>卡编号：{{dataFile.snCode}}</p>
            </view>
        </view>

        <view class="uTabs flex-center-center">
            <view class="justTab" v-for="(item,index) in dataFile.list" :key="index" @click="selected(index)">
                <p :class="{'active' : active ==(index+1)}" @click="seleType(item)"> {{item.typeName}}</p>
            </view>
        </view>

        <view class="comboTip">
            套餐说明
        </view>


        <view class="contain ">
            <view class="justDiv flex-center-center" v-for="(item,index) in networkList" :key="index"
                @click="selected1(index)" :class="{'active1' : active1 ==(index+1)}">
                <view class="justCon">
                    <p style="color:#5079ed;">{{item.price}}元</p>
                    <p>
                        {{item.amount}}{{item.unit}}/{{item.validity}}天
                    </p>
                    <p style="font-size: 24rpx; color:#999">
                        有效期{{item.validity}}天
                    </p>
                </view>
            </view>
        </view>


        <view class="footer">
            <view class="settlement">
                <view class="btn" :class="selectItem.comboId?'':'disable'" @tap="toPay">
                    {{selectItem.comboId ? '立即购买': '请选择套餐'}}
                </view>
            </view>
        </view>


    </view>
</template>

<script>
    import {
        bindMerchant,
        createOrder,
        orderPay
    } from '@/common/api.js'
    import rfNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
    export default {
        components: {
            rfNavBar
        },
        data() {
            return {
                title: '购买套餐',
                paytype: 2, //支付类型
                mpPay: true, // 是否公众号支付
                isPayLoad: false, // 是否加载支付中
                list: [],
                dataFile: '',
                active: 1,
                active1: 0,
                networkList: [],
                selectItem: {
                    comboId: null
                },
                merchantId: ''
            }
        },
        onLoad(options) {
            this.merchantId = options.merchantId
            this.intoData(options)
        },
        methods: {
            intoData(options) {
                let merchantId = options.merchantId
                if (merchantId === '' || merchantId === null || merchantId === undefined) {
                    this.$u.toast('merchantId为空，请先到设备设选择选择设备')
                } else {
                    bindMerchant(merchantId).then((res) => {
                        this.dataFile = res.data
                        if (res.data.list.length > 0) {
                            this.networkList = res.data.list[0].comboList
                        }

                    })
                }

            },
            sectionChange(index) {
                this.curIndex = index;
                this.curNow = index;
            },
            selected(index) {
                this.active = index + 1
            },
            selected1(index) {
                this.active1 = index + 1
                this.selectItem = this.networkList[index]



            },
            seleType(item) {
                this.networkList = item.comboList

            },

            toPay() {
                if (this.selectItem.comboId) {
                    uni.setStorageSync('comboItem', this.selectItem)
                    uni.setStorageSync('comboDataFile', this.dataFile)
                    uni.navigateTo({
                        url: `/pages/combo/comboOrder?merchantId=${this.merchantId}`
                    })

                }
            }
        }
    }
</script>

<style lang="scss">
    .body {
        font-size: 28rpx;

        .active {
            border-bottom: 2px solid #517af1 !important;
            color: #517af1 !important;
        }

        .active1 {
            border: 1px solid #517af1 !important;
            background-color: #edf1fd;

        }

        .backTitle {
            background-color: #5079ed;
            height: 280rpx;
            width: 100%;
            // background-image: url("../../static/icon/p_040.png");
            // background-repeat: no-repeat;
            // background-size: 30%;
            // background-position: 250px 10rpx;
            position: relative;

            .bg-image {
                width: 30%;
                position: absolute;
                top: 50rpx;
                right: 20rpx;

            }

            .titleLeft {
                position: absolute;
                color: #fff;
                margin-left: 30rpx;
                font-weight: 600;
                padding-top: 110rpx;
            }
        }

        .uTabs {
            width: 100%;

            .justTab {
                width: 50%;
                height: 84rpx;
                display: flex;
                align-items: center;
                justify-content: center;
                border-bottom: 1px solid #f4f3f3;


                p {
                    text-align: center;
                    width: 48%;
                    line-height: 80rpx;
                    height: 80rpx;
                    font-weight: 500;
                    color: #999;
                    border-bottom: 2px solid #fff;
                }
            }
        }

        .comboTip {
            width: 98%;
            height: 80rpx;
            line-height: 80rpx;
            text-align: right;
            color: #5079ed;
            margin-right: 2%;
        }


        .contain {
            width: 98%;
            margin-left: 1%;
            min-height: 210rpx;


            .justDiv {
                border-radius: 20rpx;
                border: 3rpx solid #e7e7e7;
                width: 29%;
                margin: 0 1% 20rpx 2.5%;
                height: 170rpx;
                color: #999;
                text-align: center;
                float: left;

                .justCon {
                    font-weight: 600;
                    color: #333;
                }

            }

        }

        .selectPay {
            width: 95%;
            margin-left: 3%;


            .payTitle {
                font-size: 28rpx;
                color: #000;
                font-weight: 600;

            }

            .payContent {
                .pay-list {
                    width: 100%;


                    .row {
                        width: 100%;
                        height: 120upx;
                        display: flex;
                        align-items: center;

                        .left {
                            width: 100rpx;
                            flex-shrink: 0;
                            display: flex;
                            align-items: center;

                            .icon {
                                width: 60rpx;
                                height: 60rpx;
                            }
                        }

                        .center {
                            width: 100%;
                            font-size: 30upx;
                            justify-content: left;

                        }

                        .right {
                            width: 100upx;
                            flex-shrink: 0;
                            display: flex;
                            justify-content: flex-end;
                        }
                    }
                }
            }
        }

        .footer {
            width: 100%;
            padding: 0 4%;
            background-color: #fbfbfb;
            box-sizing: border-box;
            height: 120rpx;
            display: flex;
            justify-content: flex-end;
            align-items: center;
            font-size: 28upx;
            position: fixed;
            bottom: 0upx;
            z-index: 5;
            border-top: solid 1upx #eee;

            .settlement {
                width: 100%;
                display: flex;
                justify-content: space-around;
                align-items: center;

                .sum {
                    width: 60%;
                    font-size: 32upx;
                    margin-right: 10upx;
                    display: flex;


                    .money {
                        font-weight: 600;
                        color: #5079ed;
                        font-weight: bold;
                        font-size: 36upx;
                        margin-left: 20upx;
                    }
                }

                .btn {
                    padding: 0 30upx;
                    width: 100%;
                    height: 80upx;
                    background-color: #5079ed;
                    color: #fff;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    font-size: 30upx;
                    margin-left: 20upx;
                    border-radius: 80upx;
                }

                .disable {
                    opacity: 0.6;
                }
            }
        }

    }
</style>